#include "structMeshDistribution.hpp"
#include "structMesh.hpp"
#include "timer.hpp"

using namespace hms;

StructMesh createUniformStructMesh(
	int nx, int ny, scalar dx, scalar dy, Index ng
){
	Matrix2Xs vertices (2, (nx+1)*(ny+1) );

	for (Index j{0}; j<ny+1; ++j){
		for (Index i{0}; i<nx+1; ++i){
			vertices.col(j*(nx+1)+i) =
				Array2s{i,j}*Array2s{dx,dy};
		}
	}
	return { std::move(vertices), Array2i{nx,ny}, ng };
}

int main( int argc, char** argv ){
	MPI_Init_H init(argc, argv);

	MPI_Comm_H comm { MPI_COMM_WORLD };

	Timer t;

	constexpr int maxNy { 1000 };

	std::cout.setstate( std::ios::failbit );

	for ( int i{50}; i<=maxNy; i+=50 ){
		StructMesh mesh;
		if ( comm.isMaster() ){
			mesh = createUniformStructMesh( i*2, i, 1, 1, 2 );
			t.reset();
		}
		StructMeshPart part { std::move(mesh), comm };
		if ( comm.isMaster() )
			std::cerr << i << " " << t.elapsed() << "\n";
		part.mesh().printInfo();
	}
	std::cout.clear();

	return 0;
}